var searching = 0;
//Lớp base cua module Training
function Training(baseUrl,module,controller, saction, objXml){
	this.module = module;
	this.baseUrl = baseUrl;
	this.controller = controller;
	this.saction = saction;
	this.urlPath = baseUrl + '/' + module + '/' + controller;//Biên public lưu tên module			
	this.loadding = false;
	this.tableContainer = $('#table-container');
	this.strfullTextSearch = $('#fullTextSearch').val();
	this.sformName = '';
	this.recordName = 'sách'; //Ten ban ghi
	this.dirxml = baseUrl+'/xml/view/training/index.xml';	
	this.xmlData = objXml;
	this.searchBtn = '';
	this.successLoad = function(){	
		$('div#note-process').removeClass('vY nq');
		$('div#note-process').hide();
		$('div#process').hide();
	};	
	this.statusSearch = function(){
		/*if($(this.searchBtn).attr('style') == '' || !$(this.searchBtn).attr('style'))		
			$(this.searchBtn).css('width',$(this.searchBtn).outerWidth());
		$(this.searchBtn).val('');
		$(this.searchBtn).removeClass('link-button');
		$(this.searchBtn).addClass('link-button-searching');*/
		$('#note-process').show();
		$('#loadingall').show();
		searching = 1;
	}	
	this.successSearch = function(){
		/*if($(this.searchBtn).attr('style') == '' || !$(this.searchBtn).attr('style'))		
			$(this.searchBtn).css('width',$(this.searchBtn).outerWidth());
		$(this.searchBtn).val('Tìm kiếm');
		$(this.searchBtn).addClass('link-button');
		$(this.searchBtn).removeClass('link-button-searching');*/

		$('#note-process').hide();
		$('#loadingall').hide();
		searching = 0;
	}
	var objClass = this;	
	left_menu_hide()
}
//Thay doi so row tren trang
Training.prototype.changeNumberRowPerPageModal = function(obj,functioncall){
	document.getElementById('hdn_record_number_page').value = obj.value;
	document.getElementById('hdn_current_page').value = 1;
	eval(functioncall);
}
Training.prototype.gotopageModal= function(num,functioncall){
	document.getElementById('hdn_record_number_page').value = $('#cbo_nuber_record_page').val();
	document.getElementById('hdn_current_page').value = num;	
	eval(functioncall); 
}
Training.prototype.createdata= function(data,breadcrumbs){
	var self = this
		,shtml='';
	$("#loadTreeUrl").html(breadcrumbs);
    for(var i = 0; i < data.length; i++){
        shtml += '<li class="itemli" title="'+data[i]['TD02']+'">';
        shtml += '<img width="150" height="100" src="'+ data[i]['C_FILENAME_THUMB'] + '">';
        // shorttitle
        shtml += '<label>' + shorttitle(data[i]['TD02'],19);
        shtml += '</label>';
        shtml += '<input type="checkbox" value="' + data[i]["TD01"] + '" name="chk_item_id" class="chk_item_id">';
        shtml += '</li>';
    }
    $('#table-container').html(shtml);

    // alert(jQuery('#table-container').css('padding-top'))
    self.eventdatalist();
    self.menuContent();
    reziseli();
}
Training.prototype.eventdatalist= function(){
	var self = this;
	$('li.itemli input[type="checkbox"]').click(function(){
    	markcheck();
    })
    // $('#td03')
   $('#table-container li.itemli').click(function(event){
   		if($(event.target).is(':checkbox') == false){
   			var ocheckbox = $(this).find('input[type="checkbox"]');
   			// $(ocheckbox).trigger('click');
   		   if($(ocheckbox).is(':checked'))
	           $(ocheckbox).attr('checked',false);
	       else{
	           $('.chk_item_id').attr('checked',false);
	           $(ocheckbox).attr('checked',true);
	       }
	       markcheck();
   		}
   });
   //breadcrumbs
   $('.alowclick').unbind('click');
   $('.alowclick').click(function(){
   		var pktree = $(this).attr('pktree');
   		var obj = $("#left_tree").find('li#'+pktree).find('a:first');   		
   		$(obj).trigger('click');
		$(obj).trigger('dblclick');
   })
}
function markcheck(){
	$('#table-container li.itemli').each(function(){
		if($(this).find('input[type="checkbox"]').is(':checked'))
			$(this).addClass('itemliselected');
		else
			$(this).removeClass('itemliselected');
	})
}
Training.prototype.ldmod = function(option){
	var objClass = this;
	if(searching == 1){		
		return false;		
	}else{			
		var objClass = this;	
		objClass.loadding = true;
		var url = objClass.urlPath + '/' + objClass.saction;
		var data = $('form#' + objClass.sformName).serialize();
		statusProcess();
		$.ajax({
			url: url,
			type: "POST",
			dataType: 'json',
			//cache: true,
			data:data,
			success: function(data){
				var arrResult = data.arrResult
				,breadcrumbs = data.breadcrumbs;
				if(arrResult == null) arrResult = [];
                objClass.createdata(arrResult,breadcrumbs);
				//Phan trang du lieu
				var sdocpertotal = "Danh sách này không có dữ liệu";
				$('td#generateStringNumberPage').html('');
				if(arrResult.length >0){
					var iNumberRecord = arrResult[0]['C_TOTAL_RECORD'];
					var numberRow = arrResult.length;
					$('#hdn_order').val(iNumberRecord +1);
					if(numberRow > 0)
						sdocpertotal ="Danh sách có " +numberRow + "/" + iNumberRecord + " "+objClass.recordName+".";
					var data = {iTotalRecord: iNumberRecord,
							iPage: $('form#'+objClass.sformName+' #hdn_current_page').val(),
							FuntionName:'pagingModal',
							iRowOnPage: $('#hdn_record_number_page').val()
					}
					$.ajax({
						url: baseUrl + "/public/ajax/ajax.php",
						type: "POST",
						cache: true,
						data:data,
						success: function(string){
							$('td#generateStringNumberPage').html(string);			
							var cindex = parseInt($('a.current:eq(0)').html());
							var pre = cindex - 1;
							var nex = cindex + 1;
							$('a.pre').removeAttr('onclick');
							$('a.pre').click(function(){								
								objClass.gotopageModal(pre,'this.ldmod()');
							});
							$('a.nex').removeAttr('onclick');
							$('a.nex').click(function(){								
								objClass.gotopageModal(nex,'this.ldmod()');
							});				
							$('a.pg').removeAttr('onclick');
							$('a.pg').click(function(){								
								objClass.gotopageModal(this.innerHTML,'this.ldmod()');
							});
							$('select#cbo_nuber_record_page').change(function(){																
								objClass.changeNumberRowPerPageModal(this,'this.ldmod()');
							});							
						}
					});
				}
				$('#sdocpertotal').html(sdocpertotal);					
				successProcess();
				$(this.searchBtn).attr('disable', false);
				$('form:not(form#'+objClass.sformName+')').hide();				
				$('form#' + objClass.sformName).show();				
				fixTitle();
				var paddingtop = $('#table-container').css('padding-top');
				paddingtop = parseInt(paddingtop) + 5;
				paddingtop = paddingtop +'px';
			    $('div#table-container').css('padding-top',paddingtop);
			    scrollTop(1);
			}
		});
	}
}

Training.prototype.removekey = function(key){
	shortcut.remove(key);
}
Function.prototype.inheritsFrom=function(parentClsOrObj){
    if (parentClsOrObj.constructor == Function ){
        //Normal Inheritance
        this.prototype = new parentClsOrObj;
        this.prototype.constructor = this;
        this.prototype.parent=parentClsOrObj.prototype;
    }
    else
    {
        //Pure Virtual Inheritance
        this.prototype = parentClsOrObj;
        this.prototype.constructor = this;
        this.prototype.parent = parentClsOrObj;
    }
    return this;
}
//Tạo các lớp cho từng chức năng riêng
function TrainingIndex(baseUrl,module,controller, saction,objXml){		
	this.module = module;
	this.baseUrl = baseUrl;
	this.controller = controller;
	this.saction = saction;
	this.urlPath = baseUrl + '/' + module + '/' + controller;//Biên public lưu tên module
	this.dirxml = this.baseUrl+'/xml/view/training/index.xml';		
	this.sformName = 'TrainingIndexFrm';
	this.ldmod = this.parent.ldmod;
	this.removekey = this.parent.removekey;
	this.loadTreefrm = this.parent.loadTreefrm;
	this.genTree = this.parent.genTree;	
	this.tableContainer = $('form#TrainingIndexFrm #table-container');
	this.strfullTextSearch = $('form#TrainingIndexFrm #td18').val();	
	this.searchBtn = $('form#TrainingIndexFrm #searchbtn');
//	if(objXml == ''){
//		this.xmlData = new efyXml(this.dirxml,'trainingIndexXml');
//	}else{
//		this.xmlData = objXml;
//	}
	this.loadFrmIndex();		
	this.objTree.loadTreefrm();
}
function TrainingComment(baseUrl,module,controller, saction, objXml,objXmlTemp){	
	this.module = module;
	this.baseUrl = baseUrl;
	this.controller = controller;
	this.saction = saction;
	this.urlPath = baseUrl + '/' + module + '/' + controller;//Biên public lưu tên module			
	this.dirxml = objXml;
	this.sformName = 'IndexCommentFrm';
	this.searchBtn = $('form#IndexCommentFrm #searchcmmtbtn');
	this.ldmod = this.parent.ldmod;
	this.removekey = this.parent.removekey;
	if(objXmlTemp == ''){				
		this.xmlDatacmt = new efyXml(this.dirxml,'');			
	}else{				
		this.xmlDatacmt = objXmlTemp;
	}
	this.loadFrmComment();
	this.loadGroupStaff();

}

function TrainingApprove(baseUrl,module,controller, saction, objXml,objXmlTemp){
	this.module = module;
	this.baseUrl = baseUrl;
	this.controller = controller;
	this.saction = saction;
	this.urlPath = baseUrl + '/' + module + '/' + controller;//Biên public lưu tên module			
	this.dirxml = objXml;
	this.sformName = 'IndexApproveFrm';
	this.searchBtn = $('form#IndexApproveFrm #searchApprovebtn');
	this.ldmod = this.parent.ldmod;
	this.removekey = this.parent.removekey;
	if(objXmlTemp == ''){				
		this.xmlDataApprove = new efyXml(this.dirxml,'');			
	}else{				
		this.xmlDataApprove = objXmlTemp;
	}
	this.loadFrmApprove();
	this.loadGroupStaff();
	
}
function TrainingSynthesis(baseUrl,module,controller, saction, objXml,objXmlTemp){
	this.module = module;
	this.baseUrl = baseUrl;
	this.controller = controller;
	this.saction = saction;
	this.urlPath = baseUrl + '/' + module + '/' + controller;//Biên public lưu tên module			
	this.dirxml = objXml;
	this.sformName = 'synthesisFrm';
	this.searchBtn = $('form#synthesisFrm #search');
	this.ldmod = this.parent.ldmod;
	this.removekey = this.parent.removekey;
	if(objXmlTemp == ''){				
		this.xmlDataSynthesis = new efyXml(this.dirxml,'');			
	}else{				
		this.xmlDataSynthesis = objXmlTemp;
	}
	this.loadFrmSynthesis();
	
}
//Các lớp chức năng kế thừa từ lớp module
TrainingIndex.inheritsFrom(Training);
TrainingComment.inheritsFrom(Training);
TrainingApprove.inheritsFrom(Training);
TrainingSynthesis.inheritsFrom(Training);

Training.prototype.loadGroupStaff = function(){
	var objClass = this;
	$('#UNIT').change(function(){
		data = {
			 	UNIT : $('#UNIT').val()
			 };
			$("#TD04").load(objClass.urlPath + '/groupstaff/',data,function(){
				$("#TD04").trigger("liszt:updated");
			});
	});
	$('#UNIT').trigger('change');
}
TrainingIndex.prototype.enterFrmIndex = function(){
	var objClass = this;
	shortcut.remove('Enter');		
	shortcut.add("Enter",function() {
		objClass.ldmod();
	});
}
TrainingIndex.prototype.loadFrmIndex = function(){
	var objClass = this;		
	$(this.searchBtn).click(function(){
		objClass.ldmod();
	});	
	$('form#TrainingIndexFrm #add').click(function(){
		objClass.add();
	});	
	$('form#TrainingIndexFrm #edit').click(function(){
		objClass.edit($(this));
	});	
	$('form#TrainingIndexFrm #delete').click(function(){
		objClass.del();
	});
	$('form#TrainingIndexFrm #diary').click(function(){
		objClass.showdiary();
	});		
	this.objTree = new publicTree(this,$('#td03'), $('#td03name'), this.baseUrl + '/ajax/index', 'TRAINING','index',3);
	objClass.enterFrmIndex();
	$('#TD06').change(function () {
		objClass.enterFrmIndex();
	})
	.change();
	$('#td18').focus(function(){
		objClass.enterFrmIndex();
	});
	left_menu_show();


}
TrainingIndex.prototype.showdiary = function(){
	var baseUrl = this.urlPath;
	var objClass = this;
	var p_checkbox_obj = document.getElementsByName('chk_item_id');
	v_value_list = checkbox_value_to_list(p_checkbox_obj,",");	
	if (!v_value_list) {
		jAlert("Chưa có đối tượng nào được chọn", "Thông báo !");
		return false;
	}	
	else{		
		arr_value = v_value_list.split(",");
		if (arr_value.length > 1) {
			jAlert("Chỉ được chọn một đối tượng","Thông báo !")
			return false;
		}else{
			$('#TD01hdn').val(v_value_list);
			var url = baseUrl + '/showdiary';
			data = {td01 : v_value_list};
			$.ajax({
				url: url
				,type: "POST"
				,data: data
				,success: function(string){
					$('form#TrainingIndexFrm').hide();
					$('div#load_diary').html(string);
					$('form#showdiaryFrm').show();
					$('form#showdiaryFrm .drback').click(function(){
						objClass.drback();
					});
					objClass.loadlogcmmted();
					$('#approve_log').click(function(){
						objClass.loadapproved();
					});
					$('#create_log').click(function(){
						objClass.loadlogcmmted();
					});		
				}
			});		
		}
	}
}
TrainingIndex.prototype.drback = function(){
	var objClass = this;
	$('form#showdiaryFrm').hide();
	$('form#TrainingIndexFrm').show();
	objClass.ldmod();
	fixTitle();
}
//Phương thức thêm mới
TrainingIndex.prototype.add = function(){
	var objClass = this;
	$('form').hide();
	if($('form#addTrainingfrm').length == 0){				
		var url = this.urlPath + '/add';		
		var data = {
			td03:$('form#TrainingIndexFrm #td03').val(),
			td03name:$('form#TrainingIndexFrm #td03name').val()
		};
		$.ajax({
			url: url,
			type: "POST",
			cache:false,
			data: data,		
			success: function(string){									
				$('form#TrainingIndexFrm').hide();//Ẩn dữ liệu màn hình danh sách
				$('div#load_data_form_update').html(string);//Fill dũ liệu vào thẻ div có id='load_data_form_update'
                var thumbnail = baseUrl +'/public/attach-file/default/default.jpg';
                thumbnail= '<img class="" src="'+thumbnail+'">';
                $('#listAttachThumbnail').html(thumbnail);
				$('form#addTrainingfrm').show();//Hiển thị form nhập dữ liệu theo loại hồ sơ						
				fixInformation();
			}
		});
	}else{

		$('form#addTrainingfrm').trigger('resetValues','add');
		var thumbnail = baseUrl +'/public/attach-file/default/default.jpg';
		thumbnail= '<img class="" src="'+thumbnail+'">';
		$('#listAttachThumbnail').html(thumbnail);
		$('form#addTrainingfrm').show();//Hiển thị form nhập dữ liệu theo loại hồ sơ						
		fixInformation();
	}	
}
TrainingIndex.prototype.del = function(){
	var baseUrl = this.urlPath;
	var objClass = this;
	var p_checkbox_obj = document.getElementsByName('chk_item_id');
	v_value_list = checkbox_value_to_list(p_checkbox_obj,",");	
	if (!v_value_list) {
		jAlert("Chưa có đối tượng nào được chọn", "Thông báo !");
		return false;
	}else{				
		jConfirm('Bạn thực sự muốn xóa những đối tượng đã chọn?','Xác nhận !', function(r){
			if(r){
				var url = baseUrl + '/del';		
				var data = {
					td01:v_value_list				
				};
				$.ajax({
					url: url,
					type: "POST",
					cache:false,
					data: data,		
					success: function(string){					
						objClass.ldmod();						
						fixInformation();
					}
				});							
			}			
		});
		
	}	
}
//Phương thức thêm mới
TrainingIndex.prototype.edit = function(obj){
	var baseUrl = this.urlPath;
	var objClass = this;
	// var id='';
	// $('input[name="chk_item_id"]:checked').each(function(){
	// 	text = $(this).parent().parent().find('td:eq(4)').text();
	// 	alert(text);
	// })
	var p_checkbox_obj = document.getElementsByName('chk_item_id');
	v_value_list = checkbox_value_to_list(p_checkbox_obj,",");	
	
	if (!v_value_list) {
		jAlert("Chưa có đối tượng nào được chọn", "Thông báo !");
		return false;
	}	
	else{		
		arr_value = v_value_list.split(",");
		if (arr_value.length > 1) {
			jAlert("Chỉ được chọn một đối tượng để sửa","Thông báo !")
			return false;
		}else{
			statusProcess('Đang tải dữ liệu');
			$('form').hide();
			if($('form#addTrainingfrm').length == 0){
				var url = baseUrl + '/add';
				$.ajax({
					url: url,
					type: "POST",
					cache:false,					
					success: function(string){

						$('form#TrainingIndexFrm').hide();//Ẩn dữ liệu màn hình danh sách
						$('div#load_data_form_update').html(string);//Fill dũ liệu vào thẻ div có id='load_data_form_update'
						$('form#addTrainingfrm').show();//Hiển thị form nhập dữ liệu theo loại hồ sơ						
						var url = baseUrl + '/getsingle';		
						var data = {
							td01:v_value_list				
						};
						$.ajax({
							url: url,
							type: "POST",
							cache:false,
							data: data,		
							success: function(string){					
								var arrValue = $.parseJSON(string);
								$('form#TrainingIndexFrm').hide();//Ẩn dữ liệu màn hình danh sách					
								$('form#addTrainingfrm').show();//Hiển thị form nhập dữ liệu theo loại hồ sơ								
								$('form#addTrainingfrm').trigger('update',arrValue);
								fixInformation();
								successProcess();
							}
						});							
					}
				});
			}else{
				$('form#addTrainingfrm').trigger('resetValues','add');
				$('form#addTrainingfrm').show();//Hiển thị form nhập dữ liệu theo loại hồ sơ						
				var url = baseUrl + '/getsingle';		
				var data = {
					td01:v_value_list				
				};
				$.ajax({
					url: url,
					type: "POST",
					cache:false,
					data: data,		
					success: function(string){						
						var arrValue = $.parseJSON(string);
						$('form#TrainingIndexFrm').hide();//Ẩn dữ liệu màn hình danh sách					
						$('form#addTrainingfrm').show();//Hiển thị form nhập dữ liệu theo loại hồ sơ								
						$('form#addTrainingfrm').trigger('resetValues','edit', arrValue);
						$('form#addTrainingfrm').trigger('update',arrValue);
						fixInformation();
						successProcess();
					}
				});	
				fixInformation();
			}	
		}
	}		 
}


TrainingIndex.prototype.getDep = function(){
	this.genTreeAdd($('#treeDialog'));
	$( "#dialog" ).dialog("open");
}
TrainingIndex.prototype.genTreeAdd = function(obj){		
	var url = this.baseUrl + '/ajax/index/loadtree';	
	obj.jstree({ "plugins" : ["themes","json_data","ui","crrm","dnd","search","types","hotkeys"],
			"json_data" : { 
				"ajax" : {
					"url" : url,
					"data" : function (n) { 
						return { 
							"operation" : "get_children", 
							"id" : n.attr ? n.attr("id").replace("node_","") : '',
							"sType":'TRAINING',
							"viewPer": 1
						}; 
					}
				}
			},
			"themes" : {
	            "theme" : "default",
	            "dots" : false,
	            "icons" : true,
	            "url": baseUrl + '/public/efy-js/jsTree/themes/default/style.css'
	    		}
		})
		.bind("select_node.jstree", function (event, data) {
			var per = data.rslt.obj.attr("per");
			resulter = data.inst.get_text(data.rslt.obj);
			obj.jstree("toggle_node", data.rslt.obj);				
			//Lay duong dan cua node bang js
			nodeName = data.inst.get_text(data.rslt.obj);
			parentName = data.inst.get_text(data.inst._get_parent(data.rslt.obj));
			var listName = $('#hdnpath').val();
			var listName = listName.split(',');
			if(listName.length > 2){
				for (var i = listName.length - 1; i >= 0; i--){
					if(listName[i] == parentName && parentName != '')
						break;
						listName.pop(listName[i]);
					// else listName.push(data.inst.get_text(data.rslt.obj)); 
				}
				listName = listName.join() +',';
			}
			listName += nodeName + ',';
			$('#hdnpath').val(listName);
			listName = listName.substring(0,listName.length - 1);
			listName = listName.replace(/,/gi,'/ ');
			if(per == 1){
				$('form#addTrainingfrm input#tempId').val('');				
				$('form#addTrainingfrm input#td03').val(listName);				
				$('#selectValueTreeImg').val(data.rslt.obj.attr("id"));
			}else{
				$('form#addTrainingfrm input#tempId').val(listName);				
				$('form#addTrainingfrm input#td03').val('');
				$('#selectValueTreeImg').val('');
			}
		})
		.delegate("a", "click", function (event, data) { 
			event.preventDefault(); })     
		.delegate("a","dblclick", function(e) {
			if($('form#addTrainingfrm input#td03').val() == ''){
				jAlert('Bạn chưa có quyền thêm bài giảng trong thư mục này', 'Thông báo');
				return false;
			}else{
				$( "#dialog" ).dialog("close");
			}			
		});

}

TrainingIndex.prototype.save = function(option){
	var objClass = this;				
	if(verify(document.getElementById('addTrainingfrm'))){	
		var urlUncheckattachfileList = '';
		var urlattachfileList = '';
        var urlUncheckattachfileThumbnail = '';
        var urlattachfileThumbnail = '';
        //Anh dai dien
		//Search file dinh kem
		$('form#addTrainingfrm input[id="chk_attach"]').each(function(){			
			if(this.checked)
				urlattachfileList += $(this).val() + '!~~!';
			else
				urlUncheckattachfileList += $(this).val() + '!~~!';

		});
        if($('#chk_attach:checked').length < 0){
            jAlert('Bạn phải đính kèm file!', 'Thông báo !');
            return false;
        }
        if($('#chk_attach_flash:checked').length < 0){
            jAlert('Bạn phải đính kèm file flash!', 'Thông báo !');
            return false;
        }
        $('form#addTrainingfrm input[id="chk_attach_thumb"]').each(function(){
            if(this.checked)
                urlattachfileThumbnail += $(this).val();
            else
                urlUncheckattachfileThumbnail += $(this).val();

        });
		urlUncheckattachfileList = urlUncheckattachfileList.substr(0,urlUncheckattachfileList.length -4);		
		urlattachfileList = urlattachfileList.substr(0,urlattachfileList.length -4);
		//Lay ten danh  muc sach
		var listClassCode = '';
		var listClassName = '';
		$('form#addTrainingfrm #td20 option').each(function(){
			if(this.selected){
				listClassCode += this.value + '!@!';
				listClassName += this.getAttribute('name') + '!@!';				
			}
		});
		if(listClassCode){
			listClassCode = listClassCode.substring(0, (listClassCode.length - 3));
			listClassName = listClassName.substring(0, (listClassName.length - 3));
		}

		var listAuthor = '';
		$('form#addTrainingfrm #td21 option').each(function(){
			if(this.selected){
				listAuthor += this.value + ',';		
			}
		});
		if(listAuthor){
			listAuthor = listAuthor.substring(0, (listAuthor.length - 1));
		}

		//Lay ten nhom nguoi xem
		var listGroupViewCode = '';
		var listGroupViewName = '';
		$('form#addTrainingfrm #groupuser_view option').each(function(){
			if(this.selected){
				listGroupViewCode += this.value + '!@!';
				listGroupViewName += this.getAttribute('name') + '!@!';				
			}
		});
		if(listGroupViewCode){
			listGroupViewCode = listGroupViewCode.substring(0, (listGroupViewCode.length - 3));
			listGroupViewName = listGroupViewName.substring(0, (listGroupViewName.length - 3));
		}
		//Lay ten nhom nguoi down
		var listGroupDownCode = '';
		var listGroupDownName = '';
		$('form#addTrainingfrm #groupuser_download option').each(function(){
			if(this.selected){
				listGroupDownCode += this.value + '!@!';
				listGroupDownName += this.getAttribute('name') + '!@!';				
			}
		});
		if(listGroupDownCode){
			listGroupDownCode = listGroupDownCode.substring(0, (listGroupDownCode.length - 3));
			listGroupDownName = listGroupDownName.substring(0, (listGroupDownName.length - 3));
		}
		//alert(listGroupDownCode);
		//return;
		var td06 =$('form#addTrainingfrm input[name="td06"]:checked').val();	
		var listStaff = '';		
		listStaff = checkbox2List($('div#ajax_staff15 input[name="chk_staff_id"]'), ',');
		var listStaffdown = '';		
		listStaffdown = checkbox2List($('div#ajax_staff16 input[name="chk_staff_id"]'), ',');		
		var objClass = this
			,td03 = $('form#addTrainingfrm #td03').val()
			,td03id = $('form#addTrainingfrm #td03id').val()
			,save_path = ($('form#addTrainingfrm #save_path').is(':checked')? true:false)
            ,selectValueTreeImg = $('form#addTrainingfrm #selectValueTreeImg').val()
			;
		objClass.loadding = true;
		var url = objClass.urlPath + '/savetrainingindex';			
		var data = $('form#addTrainingfrm').serialize();
		data += '&listClassCode='+ listClassCode;
		data += '&listClassName='+ listClassName;
		//Lay cac nhom nguoi
		data += '&listGroupViewCode='+ listGroupViewCode;
		data += '&listGroupViewName='+ listGroupViewName;
		data += '&listGroupDownCode='+ listGroupDownCode;
		data += '&listGroupDownName='+ listGroupDownName;
		data += '&listStaff='+ listStaff;
		data += '&listStaffdown='+ listStaffdown;
		data += '&listAuthor='+ listAuthor;
        data += '&urlattachfileThumbnail='+ urlattachfileThumbnail;
        data += '&urlUncheckattachfileThumbnail='+ urlUncheckattachfileThumbnail;
		data += '&chk_attach='+ $('#chk_attach').val();
		data += '&chk_attach_flash='+ $('#chk_attach_flash').val();

		

		statusProcess('Vui lòng đợi!<br> Hệ thống đang xử lý dữ liệu');
		$.ajax({
			url: url,
			type: "POST",
			dataType: 'json',
			//cache: true,
			data:data,
			success: function(arrResult){
				successProcess();								
				if(option == 'addNew'){
					$('form#addTrainingfrm').trigger('resetValues','add', arrResult);
					if(save_path){
						$('form#addTrainingfrm #td03').val(td03);
						$('form#addTrainingfrm #td03id').val(td03id);
                        $('form#addTrainingfrm #selectValueTreeImg').val(selectValueTreeImg);
					}
                }
				else objClass.ldmod();
			}
		});		
	}
}


function checkbox2List(obj, sep){
	var valuesList = '';	
	$(obj).each(function(){		
		if(this.checked){
			valuesList += this.value + sep;			
		}
	});
	valuesList = valuesList.substring(0, (valuesList.length - sep.length));
	return valuesList;
}

//Form Bai giang cho cho y kien
Training.prototype.ldmodcmmt = function(option){			
	var objClass = this;
	if(searching == 1){		
		return false;		
	}else{			
		this.statusSearch();				
		var objClass = this;	
		objClass.loadding = true;
		var url = objClass.urlPath + '/' + objClass.saction;	
		objClass.statusSearch();
		var data = $('form#' + objClass.sformName).serialize();		
		$.ajax({
			url: url,
			type: "POST",
			dataType: 'json',
			//cache: true,
			data:data,
			success: function(arrResult){				
				if(arrResult == null) arrResult = [];								
				objClass.xmlDatacmt.exportTable(arrResult,'',$('div#table-container-comment'),$('#TD18').val(),'IndexCommentFrm',15);
				//Phan trang du lieu
				var sdocpertotal = "Danh sách này không có dữ liệu";
				if(arrResult.length >0){
					var iNumberRecord = arrResult[0]['C_TOTAL_RECORD'];
					var numberRow = arrResult.length;
					$('#hdn_order').val(iNumberRecord +1);
					if(numberRow > 0)
						sdocpertotal ="Danh sách có " +numberRow + "/" + iNumberRecord + " "+objClass.recordName+".";
					var data = {iTotalRecord: iNumberRecord,
							iPage: $('form#'+objClass.sformName+' #hdn_current_page').val(),
							FuntionName:'pagingModal',
							iRowOnPage: $('#hdn_record_number_page').val()
					}
					$.ajax({
						url: baseUrl + "/public/ajax/ajax.php",
						type: "POST",
						cache: true,
						data:data,
						success: function(string){
							$('td#generateStringNumberPage').html(string);			
							var cindex = parseInt($('a.current:eq(0)').html());
							var pre = cindex - 1;
							var nex = cindex + 1
							$('a.pre').removeAttr('onclick');
							$('a.pre').click(function(){								
								objClass.gotopageModal(pre,'this.ldmodcmmt()');
							});
							$('a.nex').removeAttr('onclick');
							$('a.nex').click(function(){								
								objClass.gotopageModal(nex,'this.ldmodcmmt()');
							});				
							$('a.pg').removeAttr('onclick');
							$('a.pg').click(function(){								
								objClass.gotopageModal(this.innerHTML,'this.ldmodcmmt()');
							});
							$('select#cbo_nuber_record_page').change(function(){																
								objClass.changeNumberRowPerPageModal(this,'this.ldmodcmmt()');
							});							
						}
					});
				}
				$('#sdocpertotal').html(sdocpertotal);					
				successProcess();
				$('form:not(form#'+objClass.sformName+')').hide();				
				$('form#' + objClass.sformName).show();				
				fixTitle();
				//if (history.pushState) history.pushState("", "",  myClassModule.urlPath + '/#index');
			}
		});
	}
}
function lddadepicker(obj){
	$('input[date="isdate"]').each(function(){
		$(this).datepicker({
			changeMonth: true,
			gotoCurrent: true,
			minDate: new Date(1945, 1 - 1, 1),
			changeYear: true
		});
	})	
}
TrainingComment.prototype.loadFrmComment = function(){
	var objClass = this;
	this.objTree = new publicTree(this,$('#TD03'), $('#TD03name'), this.baseUrl + '/ajax/index','TRAINING','comment',0);
	this.objTree.loadTreefrm();
	$('form#IndexCommentFrm #cmmtbtn').click(function(){
		objClass.viewinfo();
	});
	$(this.searchBtn).click(function(){
		objClass.ldmodcmmt();
	});
	shortcut.remove('Enter');		
		shortcut.add("Enter",function() {
			myTrainingComment.ldmodcmmt();
		});	
	$('#TD04,#TDC02,#UNIT').change(function () {
			shortcut.remove('Enter');		
			shortcut.add("Enter",function() {
				myTrainingComment.ldmodcmmt();
			});
		})
		.change();	
	$('#TD18,#TD02,#TD08,#TD09').focus(function(){
		shortcut.remove('Enter');		
		shortcut.add("Enter",function() {
			myTrainingComment.ldmodcmmt();
		});
	})
	left_menu_hide();
}
TrainingComment.prototype.back = function(key){
	$('div#load_data_form_comment').hide();
	$('form#IndexCommentFrm').show();
	fixTitle();
	// var TDSF01 = $('#TDSF01hdn').val();
	// TDSF01 = TDSF01.substr(1,TDSF01.length - 2);
	// $('tr#'+TDSF01).remove();
	shortcut.remove('Enter');
}
TrainingComment.prototype.viewinfo = function(){
	var objClass = this;
	var TDSF01 = $('form#IndexCommentFrm input[type=checkbox][name="chk_item_id"]:checked').val();
	$('#TDSF01hdn').val(TDSF01);
	if (!TDSF01){
		jAlert('Bạn chưa xác định bài giảng cần cho ý kiến!', 'Ý kiến');
		return false;
	}
	var url = this.urlPath + '/updatecomment';
		var data = {
			TDSF01: TDSF01
		};
	$.ajax({
			url: url,
			type: "POST",
			data: data,
			//cache: true,
			//dataType: "json",		
			success: function(string){
				$('form#IndexCommentFrm').hide();
				$('div#load_data_form_comment').html(string);
				$('div#load_data_form_comment').show();
				objClass.loadUpdateCommentFrm();
			}
		});	
		 return !history.pushState;
}
TrainingComment.prototype.loadUpdateCommentFrm =  function(){
	$('form#updateCommentFrm #updatebtn,form#updateCommentFrm input.clback,form#updateCommentFrm input#deletecmmbtn,form#updateCommentFrm input#editbtn').unbind('click');
	var objClass = this;
	objClass.loadTiny();
	objClass.loadcmmted();
	$('form#updateCommentFrm #updatebtn').click(function(){
		objClass.savecmmt();
	});
	$('form#updateCommentFrm input.clback').click(function(){
		objClass.back();
	});
	$('form#updateCommentFrm input#deletecmmbtn').click(function(){
		objClass.delcmmted();
	});
	$('form#updateCommentFrm input#editbtn').click(function(){
		objClass.editcmmtedbtn();
	});
	
}
TrainingComment.prototype.editcmmtedbtn = function(){
	var objClass = this;
	if(!$('form#updateCommentFrm input[type=checkbox][name="chk_item_id"]:checked').val()){
    	jAlert('Bạn chưa chọn đối tượng nào để sửa!', 'Sửa ý kiến');
		return false;
    }
	var id = $('form#updateCommentFrm input[type=checkbox][name="chk_item_id"]:checked').val();
	if(id != ''){
		$('#TCSP01').val(id);
		var url = this.urlPath + '/editcmmted'; 
			var data = {
				TCSP01: id 
			};
		$.ajax({
			url : url,
			type: "POST",
			data: data,
			dataType: 'json',
			success: function(arrResult){
				tinyMCE.activeEditor.setContent(arrResult['TCSP04']);
				document.updateCommentFrm.TCSP03.value = arrResult['TCSP03'];
				$('#div_attach_file').empty();
				$('#div_attach_file').append(arrResult['TCSP05']);
				tinyMCE.get('sContent').focus();
				$('form#updateCommentFrm #updatebtn').unbind('click');
				$('form#updateCommentFrm #updatebtn').click(function(){
					objClass.savecmmt();
				});
			}
		});
	}
}
Training.prototype.editcmmted =function(obj,id){
    var objClass = this;
    if($(obj).find('input[name="chk_item_id"]').attr('disabled') =='disabled'){
    	jAlert('Bạn không có quyền sửa ý kiến này!', 'Sửa ý kiến');
		return false;
    }
	if(id != ''){
		$('#TCSP01').val(id);
		var url = this.urlPath + '/editcmmted'; 
			var data = {
				TCSP01: id 
			};
		$.ajax({
			url : url,
			type: "POST",
			data: data,
			dataType: 'json',
			success: function(arrResult){
				tinyMCE.activeEditor.setContent(arrResult['TCSP04']);
				document.updateCommentFrm.TCSP03.value = arrResult['TCSP03'];
				$('#div_attach_file').empty();
				$('#div_attach_file').append(arrResult['TCSP05']);
				tinyMCE.get('sContent').focus();
				$('form#updateCommentFrm #updatebtn').unbind('click');
				$('form#updateCommentFrm #updatebtn').click(function(){
					objClass.savecmmt();
				});
			}
		});
	}
}

TrainingComment.prototype.savecmmt = function(){
	var objClass = this;
	var TDSF01 = $('form#IndexCommentFrm #TDSF01hdn').val();
	var TCSP01 = $('form#updateCommentFrm #TCSP01').val();
	var sContent = tinyMCE.get('sContent').getContent();
	if(sContent == ''){
		jAlert('Bạn chưa nhập ý kiến nhận xét!', 'Cập nhật');
		return false;
	}
	if(verify(document.getElementById('updateCommentFrm'))){

				var url = this.urlPath + '/savecomment';
				var urlUncheckattachfileList = '';
				var urlattachfileList = '';		
				//Search file dinh kem
				$('form#updateCommentFrm input[id="chk_attach"]').each(function(){			
					if(this.checked)
						urlattachfileList += $(this).val() + '!~~!';
					else
						urlUncheckattachfileList += $(this).val() + '!~~!';

				});
				urlUncheckattachfileList = urlUncheckattachfileList.substr(0,urlUncheckattachfileList.length -4);		
				urlattachfileList = urlattachfileList.substr(0,urlattachfileList.length -4);		

				var data = {
					sContent: sContent 
					, TDSF01: TDSF01
					,TCSP01 : TCSP01
					,TCSP03: $('#TCSP03').val()
					,hdn_UrlattachfileList : urlattachfileList
					,urlUncheckattachfileList : urlUncheckattachfileList
				};
				$.ajax({
						url: url,
						type: "POST",
						// dataType: 'json',
						//cache: true,
						data:data,
						success: function(string){
							var str = 'Ban khong co quyen sua y kien nay';
							var n=string.indexOf(str);
							if (n > 0){
								jAlert('Bạn không có quyền sửa ý kiến này!', 'Sửa ý kiến!');
								return false;
							}else{
								objClass.loadcmmted();
								$('#TCSP01').val('');
								tinyMCE.activeEditor.setContent('');
								// $('#TCSP03').val('');
								$('#div_attach_file').empty();
								$('#div_attach_file').append($('#hdn_attachFile').val());
							}
						}
					});

	}
}
TrainingComment.prototype.loadcmmted = function(){
	var url = this.urlPath + '/loadcommented';
	var TDSF01 = $('form#IndexCommentFrm #TDSF01hdn').val();
	var data = {
		TCSP02: TDSF01
	};
	var objClass = this;
	var dirxml = baseUrl+'/xml/view/training/commented.xml';
	$.ajax({
		url: url,
		type: "POST",
		dataType: 'json',
		//cache: true,
		data:data,
		success: function(arrResult){
			if(arrResult == null) arrResult = [];
			xmlcomment.exportTable(arrResult,'',$('div#table-commented'),'','updateCommentFrm',5);
		}
	});
}
TrainingComment.prototype.delcmmted = function(){
	var objClass = this;
	var TDSF01 = $('#TDSF01').val();
	var url = this.urlPath + '/deletecmmted';
	var TCSP01s ='';
	var delimitorElement ='!~~!';
	$('form#updateCommentFrm input[type=checkbox][name="chk_item_id"]:checked').each(function(){
		TCSP01s += $(this).val() + delimitorElement;
	});
	TCSP01s = TCSP01s.substr(0,TCSP01s.length - delimitorElement.length);
	if(TCSP01s ==''){
		jAlert('Bạn chưa chọn ý kiến nào để xóa', 'Xóa');
		return false;
	}
	jConfirm('Bạn có chắc chắn muốn xóa những ý kiến này?', 'Xóa hồ sơ', function(r) {
	    if(r){
			var arrdata = {TCSP01s : TCSP01s,
							delimitorElement : delimitorElement};
			$.ajax({
				url: url,
				type: "POST",
				data: arrdata,
				cache: true,		
				success: function(string){
					objClass.loadcmmted();
				}
			});		
		}
	});

}
//Load editor
Training.prototype.loadTiny = function(){
	tinyMCE.init({
    mode : "exact", //textareas, exact,none,specific_textareas
    elements:"sContent",
    id:"sContent",
    auto_focus : "sContent",
    fix_list_elements : false,
    theme : "advanced",
    spellchecker_rpc_url: baseUrl+'/public/efy-js/tiny_mce/plugins/spellchecker/rpc.php',
    spellchecker_word_separator_chars:"\\s!\"#$%&()*+,-./:;<=>?@[\]^_{|}§©«®±¶·¸»¼½¾¿×÷¤\u201d\u201c\u00df\u00a0\u00a1",
    // fix_content_duplication : true,
    plugins : "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
    // Theme options
    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,cut,copy,paste,pastetext,pasteword,|,cut,copy,paste,pastetext,pasteword,|,forecolor,backcolor",
    theme_advanced_buttons2 : "styleselect,formatselect,fontselect,fontsizeselect,|,fullscreen,|,insertdate,inserttime,preview,",
	theme_advanced_buttons3 : "|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,",
	theme_advanced_buttons3_add : "spellchecker",
    spellchecker_languages : "+English=en,Swedish=sv",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : false,
    skin : "default",
    content_css : baseUrl+"/public/efy-style/content.css",
    theme_advanced_font_sizes: "12px,13px,14px,16px,18px,20px",
	font_size_style_values : "12px,13px,14px,16px,18px,20px",
    template_external_list_url : "lists/template_list.js",
    external_link_list_url : "lists/link_list.js",
    external_image_list_url : "lists/image_list.js",
    media_external_list_url : "lists/media_list.js",
    // Style formats
    style_formats : [
        {title : 'Bold text', inline : 'b'},
        {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
        {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
        {title : 'Example 1', inline : 'span', classes : 'example1'},
        {title : 'Example 2', inline : 'span', classes : 'example2'},
        {title : 'Table styles'},
        {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
    ],
    setup:function(inst) {
      inst.onKeyDown.add(function(inst, e) {
      	  if (e.keyCode) code = e.keyCode;
	        else if (e.which) code = e.which;
	        if(code == 9 && !e.altKey && !e.ctrlKey) {
	        	// toggle between Indent and Outdent command, depending on if SHIFT is pressed
	            if (e.shiftKey) inst.execCommand('Outdent');
	            else inst.execCommand('Indent');
	            // prevent tab key from leaving editor in some browsers
	            if(e.preventDefault) {
	                e.preventDefault();
	            }
	            return false;
	        }
      });
   }
        
});
}
// Form Bai giang da cho y kien
Training.prototype.ldmodapprove = function(option){			
	var objClass = this;
	if(searching == 1){		
		return false;		
	}else{			
		this.statusSearch();				
		var objClass = this;	
		objClass.loadding = true;
		var url = objClass.urlPath + '/' + objClass.saction;	
		objClass.statusSearch();
		var data = $('form#' + objClass.sformName).serialize();		
		$.ajax({
			url: url,
			type: "POST",
			dataType: 'json',
			//cache: true,
			data:data,
			success: function(arrResult){				
				if(arrResult == null) arrResult = [];								
				objClass.xmlDataApprove.exportTable(arrResult,'',$('div#table-container-approve'),$('#TD18').val(),'IndexApproveFrm',15);
				//Phan trang du lieu
				var sdocpertotal = "Danh sách này không có dữ liệu";
				if(arrResult.length >0){
					var iNumberRecord = arrResult[0]['C_TOTAL_RECORD'];
					var numberRow = arrResult.length;
					$('#hdn_order').val(iNumberRecord +1);
					if(numberRow > 0)
						sdocpertotal ="Danh sách có " +numberRow + "/" + iNumberRecord + " "+objClass.recordName+".";
					var data = {iTotalRecord: iNumberRecord,
							iPage: $('form#'+objClass.sformName+' #hdn_current_page').val(),
							FuntionName:'pagingModal',
							iRowOnPage: $('#hdn_record_number_page').val()
					}
					$.ajax({
						url: baseUrl + "/public/ajax/ajax.php",
						type: "POST",
						cache: true,
						data:data,
						success: function(string){
							$('td#generateStringNumberPage').html(string);			
							var cindex = parseInt($('a.current:eq(0)').html());
							var pre = cindex - 1;
							var nex = cindex + 1
							$('a.pre').removeAttr('onclick');
							$('a.pre').click(function(){								
								objClass.gotopageModal(pre,'this.ldmodapprove()');
							});
							$('a.nex').removeAttr('onclick');
							$('a.nex').click(function(){								
								objClass.gotopageModal(nex,'this.ldmodapprove()');
							});				
							$('a.pg').removeAttr('onclick');
							$('a.pg').click(function(){								
								objClass.gotopageModal(this.innerHTML,'this.ldmodapprove()');
							});
							$('select#cbo_nuber_record_page').change(function(){																
								objClass.changeNumberRowPerPageModal(this,'this.ldmodapprove()');
							});								
						}
					});
				}
				$('#sdocpertotal').html(sdocpertotal);					
				successProcess();
				$('form:not(form#'+objClass.sformName+')').hide();				
				$('form#' + objClass.sformName).show();				
				fixTitle();
				//if (history.pushState) history.pushState("", "",  myClassModule.urlPath + '/#index');
			}
		});
	}
}
TrainingApprove.prototype.viewapprove = function(){
	var objClass = this;
	var TD01 = $('form#IndexApproveFrm input[type=checkbox][name="chk_item_id"]:checked').val();
	$('#TD01hdn').val(TD01);
	if (!TD01){
		jAlert('Bạn chưa xác định bài giảng cần cho ý kiến!', 'Ý kiến');
		return false;
	}
	var url = this.urlPath + '/updateapprove';
		var data = {
			TD01: TD01
		};
	$.ajax({
			url: url,
			type: "POST",
			data: data,
			//cache: true,
			//dataType: "json",		
			success: function(string){
				$('form#IndexApproveFrm').hide();
				$('div#load_data_form_approve').html(string);
				$('div#load_data_form_approve').show();
				objClass.loadUpdateApproveFrm();
			}
		});	
		 return !history.pushState;
}
TrainingApprove.prototype.back = function(key){
	$('div#load_data_form_approve').hide();
	$('form#IndexApproveFrm').show();
	fixTitle();
	shortcut.remove('Enter');
}
TrainingApprove.prototype.loadUpdateApproveFrm = function(){
	var objClass = this;
	objClass.loadTiny();
	$('form#updateApproveFrm input.clback').click(function(){
		objClass.back();
	});
	$('form#updateApproveFrm #updatebtn').click(function(){
		objClass.saveapprove();
	});
	$('form#updateApproveFrm input.deletebtn').click(function(){
		objClass.delapprove();
	});
	$('form#updateApproveFrm input#editbtn').click(function(){
		objClass.editapprovedbtn();
	});
	 $('input[name="approve_radio"]').click(function(){
	 	var LeaderName = $('#LeaderNameHdn').val();
		var CreaterName = $('#CreaterNameHdn').val();
		var approve_radio = $('input[name="approve_radio"]:checked').val();
		if (approve_radio == 'DA_DUYET'){
			var contents = 'Sau khi xem xét nội dung bài giảng, tôi '+LeaderName+ ' đồng ý duyệt nội dung bài giảng của đồng chí '+CreaterName+'.';
			tinyMCE.activeEditor.setContent(contents);
		}else{
			var contents = 'Sau khi xem xét nội dung bài giảng, tôi '+LeaderName+ ' không đồng ý duyệt nội dung bài giảng của đồng chí '+CreaterName+' vì.....';
			tinyMCE.activeEditor.setContent(contents);
			tinyMCE.get('sContent').focus();
		}
	 });
	objClass.loadlogcmmted();	
	$('#approve_log').click(function(){
			objClass.loadapproved();
	});
	$('#create_log').click(function(){
			objClass.loadlogcmmted();
	});	
}
Training.prototype.loadlogcmmted = function(){
	var url = this.urlPath + '/loadcommented';
	var TD01 = $('form#IndexApproveFrm #TD01hdn').val();
	if(!$('form#IndexApproveFrm #TD01hdn').val())
		TD01 = $('form#TrainingIndexFrm input[type=checkbox][name="chk_item_id"]:checked').val();
	var data = {
		TD01: TD01
	};
	var objClass = this;
	var dirxml = baseUrl+'/xml/view/training/commented.xml';
	$.ajax({
		url: url,
		type: "POST",
		dataType: 'json',
		//cache: true,
		data:data,
		success: function(arrResult){
			if(arrResult == null) arrResult = [];
			if($('form#TrainingIndexFrm input[type=checkbox][name="chk_item_id"]:checked').val())
				 xmlcomment.exportTable(arrResult,'',$('div#table-approved'),'','showdiaryFrm',10);
			else xmlcomment.exportTable(arrResult,'',$('div#table-approved'),'','updateApproveFrm',5);
			$('#create_log').attr('style','color: blue;');
			$('#approve_log').removeAttr('style');
		}
	});
}
Training.prototype.loadapproved = function(){
	var url = this.urlPath + '/loadapproved';
	var TD01 = $('form #TD01hdn').val();
	var data = {
		TD01: TD01
	};
	var objClass = this;
	var dirxml = baseUrl+'/xml/view/training/approved.xml';
	$.ajax({
		url: url,
		type: "POST",
		dataType: 'json',
		//cache: true,
		data:data,
		success: function(arrResult){
			if(arrResult == null) arrResult = [];
			if($('form#TrainingIndexFrm input[type=checkbox][name="chk_item_id"]:checked').val())
				xmlapprove.exportTable(arrResult,'',$('div#table-approved'),'','showdiaryFrm',10);
			else	
				xmlapprove.exportTable(arrResult,'',$('div#table-approved'),'','updateApproveFrm',5);
			$('#approve_log').attr('style','color: blue;');
			$('#create_log').removeAttr('style');
		}
	});
}
TrainingApprove.prototype.loadFrmApprove = function(){
	var objClass = this;
	this.objTree = new publicTree(this,$('#TD03'), $('#TD03name'), this.baseUrl + '/ajax/index','TRAINING','approve',0);
	this.objTree.loadTreefrm();
	$('form#IndexApproveFrm #approvebtn').click(function(){
		objClass.viewapprove();
	});
	$(this.searchBtn).click(function(){
		objClass.ldmodapprove();
	});
	shortcut.remove('Enter');		
		shortcut.add("Enter",function() {
			myTrainingApprove.ldmodapprove();
		});
	$('#TD04,#TDC02,#UNIT').change(function () {
			shortcut.remove('Enter');		
			shortcut.add("Enter",function() {
				myTrainingApprove.ldmodapprove();
			});
		})
		.change();
	$('#TD18,#TD02,#TD08,#TD09').focus(function(){
		shortcut.remove('Enter');		
		shortcut.add("Enter",function() {
			myTrainingApprove.ldmodapprove();
		});
	});
	left_menu_hide();
}
TrainingApprove.prototype.saveapprove = function(){
	objClass = this;
	if(!$('#approve_log').attr('style')){
		jAlert('Bạn chưa chọn "Nhật ký duyệt nội dung soạn giảng" để phê duyệt!', 'Phê duyệt');
		objClass.loadapproved();
		return false;
	}
	if(verify(document.getElementById('updateApproveFrm'))){
		if(!$('input[name="approve_radio"]:checked').val()){
			jAlert('Bạn chưa chọn trạng thái phê duyệt!', 'Cập nhật');
			return false;
		}
		var sContent = tinyMCE.get('sContent').getContent();
		if(sContent == ''){
			jAlert('Bạn chưa nhập ý kiến nhận xét!', 'Cập nhật');
			return false;
		}
		var url = this.urlPath + '/saveapprove';
		var urlUncheckattachfileList = '';
		var urlattachfileList = '';		
		//Search file dinh kem
		$('form#updateApproveFrm input[id="chk_attach"]').each(function(){			
			if(this.checked)
				urlattachfileList += $(this).val() + '!~~!';
			else
				urlUncheckattachfileList += $(this).val() + '!~~!';

		});
		urlUncheckattachfileList = urlUncheckattachfileList.substr(0,urlUncheckattachfileList.length -4);		
		urlattachfileList = urlattachfileList.substr(0,urlattachfileList.length -4);		
		var data = {
			sContent: sContent 
			,TIL01:  $('#TIL01').val()
			,TD01:   $('#TD01hdn').val()
			,TIL04 : $('#TIL04').val()
			,TIL07 : $('input[name="approve_radio"]:checked').val()
			,hdn_UrlattachfileList : urlattachfileList
			,urlUncheckattachfileList : urlUncheckattachfileList
		};
		$.ajax({
			url:url,
			type:"POST",
			// dataType: 'json',
			data: data,
			success: function(){
				objClass.back();
				objClass.ldmodapprove();
				// objClass.loadapproved();
				// tinyMCE.activeEditor.setContent('');
				// $('#TIL01').val('');
				// $('input[name="approve_radio"]').removeAttr('checked');
				// $('#div_attach_file').empty();
				// $('#div_attach_file').append($('#hdn_attachFile').val());
			}
		});
	}
}
TrainingApprove.prototype.delapprove = function(){
	var objClass = this;
	var TD01 = $('#TD01hdn').val();
	var url = this.urlPath + '/delapproved';
	var TIL01s ='';
	var delimitorElement ='!~~!';
	$('form#updateApproveFrm input[type=checkbox][name="chk_item_id"]:checked').each(function(){
		TIL01s += $(this).val() + delimitorElement;
	});
	TIL01s = TIL01s.substr(0,TIL01s.length - delimitorElement.length);
	if(TIL01s ==''){
		jAlert('Bạn chưa chọn ý kiến nào để xóa', 'Xóa');
		return false;
	}
	jConfirm('Bạn có chắc chắn muốn xóa những ý kiến phê duyệt này?', 'Xóa hồ sơ', function(r) {
	    if(r){
			var arrdata = {TIL01s : TIL01s,
							delimitorElement : delimitorElement};
			$.ajax({
				url: url,
				type: "POST",
				data: arrdata,
				cache: true,		
				success: function(string){
					objClass.loadapproved();
				}
			});		
		}
	});
}
TrainingApprove.prototype.editapprovedbtn = function(){
	var objClass = this;
	if(!$('#approve_log').attr('style')){
		jAlert('Bạn chưa chọn "Nhật ký duyệt nội dung soạn giảng" để sửa!', 'Sửa ý kiến');
		return false;
	}
	if(!$('form#updateApproveFrm input[type=checkbox][name="chk_item_id"]:checked').val()){
    	jAlert('Bạn chưa chọn đối tượng nào để sửa!', 'Sửa ý kiến');
		return false;
    }else{
		var id = $('form#updateApproveFrm input[type=checkbox][name="chk_item_id"]:checked').val();
		if(id != ''){
			$('#TIL01').val(id);
			var url = this.urlPath + '/editapproved'; 
				var data = {
					TIL01: id 
				};
			$.ajax({
				url : url,
				type: "POST",
				data: data,
				dataType: 'json',
				success: function(arrResult){
					tinyMCE.activeEditor.setContent(arrResult['TIL05']);
					document.updateApproveFrm.TIL04.value = arrResult['TIL04'];
					$('#'+arrResult['TIL07']+'').attr('checked','true');
					$('#div_attach_file').empty();
					$('#div_attach_file').append(arrResult['TIL06']);
					tinyMCE.get('sContent').focus();
					$('form#updateApproveFrm #updatebtn').unbind('click');
					$('form#updateApproveFrm #updatebtn').click(function(){
						objClass.saveapprove();
					});
				}
			});
		}
    } 
}

//Form tong hop tinh hinh nhap bai giang cua can bo
Training.prototype.ldmodsynthesis = function(option){			
	var objClass = this;
	if(searching == 1){		
		return false;		
	}else{			
		this.statusSearch();				
		var objClass = this;	
		objClass.loadding = true;
		var url = objClass.urlPath + '/' + objClass.saction;	
		objClass.statusSearch();
		var data = $('form#' + objClass.sformName).serialize();		
		$.ajax({
			url: url,
			type: "POST",
			dataType: 'json',
			//cache: true,
			data:data,
			success: function(arrResult){	
				if(arrResult == null) arrResult = [];								
				objClass.xmlDataSynthesis.exportTable(arrResult,'',$('div#table-content'),'','synthesisFrm',100);
				//Phan trang du lieu
				var sdocpertotal = "Danh sách này không có dữ liệu";
				if(arrResult.length >0){
					var iNumberRecord = arrResult[0]['C_TOTAL_RECORD'];
					var numberRow = arrResult.length;
					$('#hdn_order').val(iNumberRecord +1);
					if(numberRow > 0)
						sdocpertotal ="Danh sách có " +numberRow + "/" + iNumberRecord + " cán bộ.";
					var data = {iTotalRecord: iNumberRecord,
							iPage: $('form#'+objClass.sformName+' #hdn_current_page').val(),
							FuntionName:'pagingModal',
							iRowOnPage: $('#hdn_record_number_page').val()
					}
					$.ajax({
						url: baseUrl + "/public/ajax/ajax.php",
						type: "POST",
						cache: true,
						data:data,
						success: function(string){
							$('td#generateStringNumberPage').html(string);			
							var cindex = parseInt($('a.current:eq(0)').html());
							var pre = cindex - 1;
							var nex = cindex + 1
							$('a.pre').removeAttr('onclick');
							$('a.pre').click(function(){								
								objClass.gotopageModal(pre,'this.ldmodsynthesis()');
							});
							$('a.nex').removeAttr('onclick');
							$('a.nex').click(function(){								
								objClass.gotopageModal(nex,'this.ldmodsynthesis()');
							});				
							$('a.pg').removeAttr('onclick');
							$('a.pg').click(function(){								
								objClass.gotopageModal(this.innerHTML,'this.ldmodsynthesis()');
							});
							$('select#cbo_nuber_record_page').change(function(){																
								objClass.changeNumberRowPerPageModal(this,'this.ldmodsynthesis()');
							});							
						}
					});
				}
				$('#sdocpertotal').html(sdocpertotal);					
				successProcess();
				$('form:not(form#'+objClass.sformName+')').hide();				
				$('form#' + objClass.sformName).show();				
				fixTitle();
				//if (history.pushState) history.pushState("", "",  myClassModule.urlPath + '/#index');
			}
		});
	}
}
TrainingSynthesis.prototype.loadFrmSynthesis = function(){
	objClass = this;
	$('#0').attr('checked','checked');
	$('form#synthesisFrm input.search').click(function(){
			objClass.ldmodsynthesis();
	});
	$('input[type=radio][name="status"]').click(function(){
		status = $('input[type=radio]:checked').val();
		objClass.ldmodsynthesis();
	});
	//Khi kết xuất báo cáo
	$('input.clprintf').click(function(){
		objClass.printf();
	})
	objClass.enterFrmSynthesis();
}
TrainingSynthesis.prototype.enterFrmSynthesis = function(){
	var objClass = this;
	shortcut.remove('Enter');		
	shortcut.add("Enter",function() {
		objClass.ldmodsynthesis();
	});
}
TrainingSynthesis.prototype.printf = function(){
	var kieuin = 'excel';
	var count = 0;
	var url = urlPath + '/indexsynthesis';
	var data = $('form#synthesisFrm').serialize()+'&kieuin='+kieuin;
	open_load_data_process();
    $.ajax({
		url: url,
		type: "POST",
		data: data,
		//cache: true,
		success: function(string){
			close_load_data_process();
			open_modal_export_file(kieuin,string);
		}
	});
}

function fixeditthumbnail(){
	// $('#uploadThumbnail');
}

Training.prototype.menuContent = function(){
	var self = this
		,oItem =$('#table-container li.itemli');
	$(oItem).unbind('contextmenu');
	var func = function(e){
		$("div.popup").remove();
	    var obj = $(this);
		$('#table-container li.itemli input[type="checkbox"]').attr('checked',false);
		$(obj).find('input[type="checkbox"]').attr('checked',true);
		markcheck();
      	var htmls = '<div class="popup menuelement"><ul>';
      	htmls += '<li id="addcontent" class="">Thêm</li>';
      	htmls += '<li id="editcontent" class="">Sửa</li>';
      	htmls += '<li id="deletecontent" class="">Xóa</li>';
      	htmls += '<li id="viewcontent" class="">Theo dõi ý kiến</li>';
      	htmls += '</ul></div>';
      	$(htmls).appendTo("body")
        	.css("left", e.pageX)
        	.css("top", e.pageY)
        	.show();
	    // Them
	  	$('.popup li#addcontent').bind("click",function(){
			// $(obj).trigger('click');
			$('input.addrecord').trigger('click');
	  	});
	  	// Sua
	  	$('.popup li#editcontent').bind("click",function(){
			// $(obj).trigger('click');
			$('input.editecord').trigger('click');
	  	});
	  	// Xoa
	  	$('.popup li#deletecontent').bind("click",function(){
			// $(obj).trigger('click');
			$('input.deleterecord').trigger('click');
	  	});
	  	// Theo doi y kien
	  	$('.popup li#viewcontent').bind("click",function(){
			// $(obj).trigger('click');
			$('input.diaryIdea').trigger('click');
	  	});
	  	
      	e.preventDefault();
      	return false;
	}
	// Create event
	$(oItem).bind('contextmenu', func);
}





